<?php
/**
 *  Created by Mient-jan Stelling [mient-jan@mediamonks.com].
 *  Copyright (c) 2008 MediaMonks. All rights reserved.
 */

require_once 'Zend/Db/Table/Rowset/Abstract.php';

/**
 * Spectus_Table_Row_Abstract
 *
 * @todo major recode of class 
 * @author Mient-jan Stelling
 **/
abstract class Spectus_Default_Table_Rowset_Abstract extends Zend_Db_Table_Rowset_Abstract // implements  SeekableIterator, Countable, ArrayAccess
{
	public $_parent = NULL;

//    public function __construct(array $config)
//	{
//		// set parent data
//		if( isset($config['parent']))
//		{
//			$this->_parent = $config['parent'];
//		}
//		
//		parent::__construct( $config );
//	}
	
	/**
 	 * getTableClassName method 
 	 *
 	 * @return 
 	 * @author Mient-jan Stelling
 	 **/	
	public function getTableClassName()
	{
		return $this->_tableClass ;
	}

	/**
 	 * getTableclass method 
 	 *
 	 * @return 
 	 * @author Mient-jan Stelling
 	 **/	
	public function getTableClass()
	{
		return $this->_table;
	}

	/**
 	 * getTableClassName method 
 	 *
 	 * @return 
 	 * @author Mient-jan Stelling
 	 **/	
//	public function getTableInfo( $argStr = NULL )
//	{
//		return $this->_table->info( $argStr );
//	}
		
    /**
     * Check if an offset exists
     * Required by the ArrayAccess implementation
     *
     * @param string $offset
     * @return boolean
     */
    public function offsetExists($offset)
    {
        return isset($this->_data[(int) $offset]);
    }
    
    /**
     * Get the row for the given offset
     * Required by the ArrayAccess implementation
     *
     * @param string $offset
     * @return Zend_Db_Table_Row_Abstract
     */
    public function offsetGet($offset)
    {
        $this->_pointer = (int) $offset;

        return $this->current();
    }

    public function isEnd()
    {
		return ( $this->_pointer == $this->_count );
    }
    
	public function add( Spectus_Default_Table_Row_Abstract $argObjRow )
	{
		$this->_rows[] = $argObjRow;
		$this->_data[] = $argObjRow->toArray();
		
		$this->_count = count($this->_data);
	}
    
	public function truncate()
	{
		$this->_data = array();
		$this->_rows = array();
		$this->_count = 0;
	}
    
    /**
     * Does nothing
     * Required by the ArrayAccess implementation
     *
     * @param string $offset
     * @param mixed $value
     */
    public function offsetSet($offset, $value)
    {

    	
    }
    
    /**
     * Does nothing
     * Required by the ArrayAccess implementation
     *
     * @param string $offset
     */
    public function offsetUnset($offset)
    {
    }
	
    /**
     * creates a xml string of all the data
     *
     * @return string
     */
	public function toXml()
	{
		$strXml = '';
		foreach ( $this as $objRow )
		{
			$strXml .= '<row>' . $objRow->toXml() . '</row>';
		}
		
		return $strXml;
	}
}